﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.MVC.Model;
using System.Data.Linq;

namespace Project.MVC.MsSQLDAL
{
    static class General
    {
        #region User
        internal static UserInfo GetInfo(User value)
        {
            if (value == null)
                return null;
            else
                return new UserInfo
                {
                    Id = value.Id,
                    HoTen = value.HoTen,
                    UserName = value.UserName,
                    Password = value.Password,
                    TimeInput = value.TimeInput,
                    Status = value.Status
                };
        }

        internal static User GetInfo(UserInfo value)
        {
            if (value == null)
                return null;
            else
                return new User
                {
                    Id = value.Id,
                    HoTen = value.HoTen,
                    UserName = value.UserName,
                    Password = value.Password,
                    TimeInput = value.TimeInput,
                    Status = value.Status
                };
        }

        internal static List<UserInfo> GetList(EntitySet<User> data)
        {
            var list = new List<UserInfo>();
            if (data != null)
            {
                foreach (var value in data)
                {
                    list.Add(GetInfo(value));
                }
            }
            return list;
        }
        #endregion

        #region Category
        internal static CategoryInfo GetInfo(Category value)
        {
            if (value == null)
                return null;
            else
                return new CategoryInfo
                {
                    Id = value.Id,
                    ParentId = value.ParentId,
                    Title = value.Title
                };
        }

        internal static Category GetInfo(CategoryInfo value)
        {
            if (value == null)
                return null;
            else
                return new Category
                {
                    Id = value.Id,
                    ParentId = value.Id,
                    Title = value.Title
                };
        }

        internal static List<CategoryInfo> GetList(EntitySet<Category> data)
        {
            var list = new List<CategoryInfo>();
            if (data != null)
            {
                foreach (var value in data)
                {
                    list.Add(GetInfo(value));
                }
            }
            return list;
        }
        #endregion

        #region Image
        internal static ImageInfo GetInfo(Image value)
        {
            if (value == null)
                return null;
            else
                return new ImageInfo
                {
                    Id = value.Id,
                    ProductId = value.ProductId,
                    IsDefault = value.IsDefault,
                    Url = value.Url
                };
        }

        internal static Image GetInfo(ImageInfo value)
        {
            if (value == null)
                return null;
            else
                return new Image
                {
                    Id = value.Id,
                    ProductId = value.ProductId,
                    IsDefault = value.IsDefault,
                    Url = value.Url
                };
        }

        internal static List<ImageInfo> GetList(EntitySet<Image> data)
        {
            var list = new List<ImageInfo>();
            if (data != null)
            {
                foreach (var value in data)
                {
                    list.Add(GetInfo(value));
                }
            }
            return list;
        }
        #endregion

        #region Product
        internal static ProductInfo GetInfo(Product value)
        {
            if (value == null)
                return null;
            else
                return new ProductInfo
                {
                    Id = value.Id,
                    Title = value.Title,
                    Description = value.Description,
                    CategoryId = value.CategoryId,
                    ImageList = General.GetList(value.Images)
                };
        }

        internal static Product GetInfo(ProductInfo value)
        {
            if (value == null)
                return null;
            else
                return new Product
                {
                    Id = value.Id,
                    Title = value.Title,
                    Description = value.Description,
                    CategoryId = value.CategoryId,
                };
        }

        internal static List<ProductInfo> GetList(EntitySet<Product> data)
        {
            var list = new List<ProductInfo>();
            if (data != null)
            {
                foreach (var value in data)
                {
                    list.Add(GetInfo(value));
                }
            }
            return list;
        }
        #endregion

        #region Contact
        internal static ContactInfo GetInfo(Contact value)
        {
            if (value == null)
                return null;
            else
                return new ContactInfo
                {
                    Id = value.Id,
                    Company = value.Company,
                    Address = value.Address,
                    Email = value.Email,
                    Phone = value.Phone,
                    Fax = value.Fax,
                    AboutUs = value.AboutUs,
                    Yahoo = value.Yahoo,
                    Sky = value.Sky,
                    Sologan=value.Sologan
                };
        }

        internal static Contact GetInfo(ContactInfo value)
        {
            if (value == null)
                return null;
            else
                return new Contact
                {
                    Id = value.Id,
                    Company = value.Company,
                    Address = value.Address,
                    Email = value.Email,
                    Phone = value.Phone,
                    Fax = value.Fax,
                    AboutUs = value.AboutUs,
                    Yahoo = value.Yahoo,
                    Sky = value.Sky,
                    Sologan=value.Sologan
                };
        }

       
        #endregion
    }
}
